package com.mazaiting.instructions.math;

import com.mazaiting.instructions.base.NoOperandsInstruction;
import com.mazaiting.rtda.MtFrame;
import com.mazaiting.rtda.MtOperandStack;

/**
 * 按位与指令
 * 只能操作int和long变量
 * @author mazaiting
 * @since 2021/8/15
 */
public class AndInstruction {

    /**
     * 整型按位与
     */
    public static class IAnd extends NoOperandsInstruction {
        @Override
        public void execute(MtFrame frame) {
            MtOperandStack stack = frame.getOperandStack();
            int v1 = stack.popInt();
            int v2 = stack.popInt();
            int result = v1 & v2;
            stack.pushInt(result);
        }
    }

    /**
     * 长整型按位与
     */
    public static class LAnd extends NoOperandsInstruction {
        @Override
        public void execute(MtFrame frame) {
            MtOperandStack stack = frame.getOperandStack();
            long v1 = stack.popLong();
            long v2 = stack.popLong();
            long result = v1 & v2;
            stack.pushLong(result);
        }
    }
}
